{include file="common/header"}
<body>
<div class="x-nav hide">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加菜单','{:url("add")}')"><i class="layui-icon"></i>添加菜单</button>
    </xblock>
    <table class="layui-table layui-form">
        <thead>
        <tr>
            <th>ID</th>
            <th>图标</th>
            <th>菜单名称</th>
            <th>所属控制器</th>
            <th>操作方法</th>
            <th>菜单显示</th>
            <th>操作</th></tr>
        </thead>
        <tbody>
        {foreach $list as $vo}
        <tr>
            <td>{$vo.id}</td>
            <td><i class="icon iconfont">{:html_entity_decode('&'.$vo.icon)}</i></td>
            <td>{:html_entity_decode($vo.str)}{$vo.title}</td>
            <td>{$vo.controller}</td>
            <td>{$vo.methods}</td>
            <td><input type="checkbox" lay-filter="switch" lay-skin="switch" value="{$vo.id}" {if $vo.is_nav == 1}checked{/if} lay-text="ON|OFF"></td>
            <td class="td-manage">
                <a title="编辑"  onclick="x_admin_show('编辑','{:url("edit")}?id={$vo.id}')" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" onclick="member_del(this,'{$vo.id}')" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>

</div>
<script>
    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $.get("{:url('del')}",{id:id},function (res) {
                if (res.success){
                    $(obj).parents("tr").remove();
                    layer.msg(res.msg,{icon:1,time:1000});
                }else{
                    layer.msg(res.msg,{icon:2,time:1000});
                }
            });

        });
    }
    layui.use(['form'],function () {
        var form = layui.form;
        form.on('switch(switch)', function(data){
            var id = data.value,
                is_nav = 0;
            if (data.elem.checked){
                is_nav = 1;
            }
            var load = layer.load(1);
            $.post("{:url('edit')}",{
                id:id,
                data:{
                    is_nav:is_nav
                }
            },function (res) {
                layer.close(load);
                if (res.success){
                    layer.msg(res.msg,{icon:1})
                } else{
                    layer.msg(res.msg,{icon:2})
                }
            });
        });
    })
</script>
</body>

</html>